;
(function() {
	'use strict';
	angular.module('services.omdisplay.operationDevelop')
		.service('odProblem', OdProblem)
		.service('pageBindData', PageBindData)
		.factory('sdsOperationDevelopService', odService);

	function OdProblem(pageBindData, sdsOperationDevelopService) {
		this.pageBindData = PageBindData;
		this.sdsOperationDevelopService = sdsOperationDevelopService;
	}

	function odService(Restangular) {
		return {
			queryChannelProblem: function(params, callback) {
				Restangular.all('sas/OMdisplay/omWork').post(params).then(callback);
			},
			qeuryBuinessName: function(params, callback) {
				Restangular.all('sas/common/businessQuery').post(params).then(callback);
			},
			queryBusinessProblems: function(params, callback) {
				Restangular.all('sas/OMdisplay/businessContrast').post(params).then(callback);
			},
			queryChannelProblems: function(params, callback) {
				Restangular.all('sas/OMdisplay/channelContrast').post(params).then(callback);
			},
			getPageBind: function() {
				var year = new Date().getFullYear();
				var month = new Date().getMonth();
				var day = new Date().getDate();
				return {
					startTime: new Date(year, month, day),
					endTime: new Date(year, month, day),
					system: '11',
					business: [],
					channel: [],
					timeType: '1'
				};
			},
			getEchartsData: function(items, title) {
				var temp = {
					echartsTitleText: title,
					echartsLegend: ['UPAY问题数'],
					echartsXData: [],
					echartsSeries: []
				};
				angular.forEach(items, function(item) {
					if (temp.echartsXData.indexOf(item.channelName) === -1) {
						temp.echartsXData.push(item.channelName);
					}
					temp.echartsSeries.push(item.total);
				});
				var myOption = this.showEcharts(temp);
				return myOption;
			},
			showEcharts: function(temp) {
				var option = {
					title: {
						text: temp.echartsTitleText,
						x: 'center'
					},
					animation: false,
					tooltip: {
						show: true
					},
					grid: {
						x2: 120
					},
					legend: {
						show: true,
						orient: 'vertical',
						data: temp.echartsLegend,
						x: 'right',
						y: 'center'
					},
					xAxis: [{
						type: 'category',
						data: temp.echartsXData
					}],
					yAxis: [{
						type: 'value',
						boundaryGap: [0, 0.01]
					}],
					series: [{
						name: 'UPAY问题数',
						type: 'bar',
						barMaxWidth: 120,
						data: temp.echartsSeries
					}]
				};
				return option;
			},
			getTimeTypes: function() {
				return [{
					timeTypeCode: '1',
					timeTypeName: '日'
				}, {
					timeTypeCode: '3',
					timeTypeName: '月'
				}];
			}
		};
	}

	function PageBindData() {
		this.contents = [];
	}
})();